home *** CD-ROM | disk | FTP | other *** search
/ com!online 2002 July / com!online0702.iso / software / livemotion / DATA1.CAB / Automation / Scripts / Star Maker.js < prev    next >
Encoding:
Text File  |  2002-05-13  |  3.1 KB  |  83 lines

  1. /***************************************************************
  2. ADOBE SYSTEMS INCORPORATED 
  3. Copyright 2002 Adobe Systems Incorporated 
  4. All Rights Reserved 
  5.  
  6. NOTICE:  Adobe permits you to use, modify, and distribute this 
  7. file in accordance with the terms of the Adobe license agreement 
  8. accompanying it.  If you have received this file from a source 
  9. other than Adobe, then your use, modification, or distribution
  10. of it requires the prior written permission of Adobe. 
  11. ***************************************************************/
  12.  
  13. /***************************************************************
  14. Author: Henry Lee
  15. ***************************************************************/
  16.  
  17. /***************************************************************
  18.  
  19. This script will create a start on the current composition.  If
  20. an object is currently selected, it will be converted into a 
  21. geometric object, then reshaped into a star.
  22.  
  23. Function:
  24.     star(inRad,outRad,thepoints,offsetPoints)
  25.  
  26. Arguments:
  27.     <inRad> integer - the inner radius of the star
  28.     <outRad> integer - the outer radius of the star
  29.     <thepoints> integer - the number of points of the star
  30.     <offsetPoints> integer - the angle at which to offset each
  31.         point of the star.
  32.  
  33. ***************************************************************/
  34.  
  35. /***************************************************************
  36. To change the behavior of this script, make your changes below
  37. ***************************************************************/
  38.  
  39. star(25, 45, 5, 0);
  40.  
  41. /***************************************************************
  42. DO NOT EDIT BELOW THIS LINE
  43. ***************************************************************/
  44.  
  45. function star(inRad, outRad, thepoints, offsetPoints) {
  46.     comp = application.currentComposition;
  47.     if (comp.selection.length < 1) {
  48.         thestar = comp.createObject(LMGeometricType.path, comp.size.x/2, comp.size.y/2, 0);
  49.     } else {
  50.         thestar = comp.selection[0].convertType(LMGeometricType.path);
  51.     }
  52.  
  53.     comp.saveSelection()
  54.     var degToRads = Math.PI/180;
  55.     var outOffset = offsetPoints * degToRads;
  56.     var anglePerPoint = 2*Math.PI/thepoints; 
  57.     var anglePerKnot = anglePerPoint/2 + outOffset; 
  58.     var angleOffset  = Math.PI/2;  // so a point is straight up
  59.     var startAngle = 0 + angleOffset; 
  60.     var endAngle = 2*Math.PI + angleOffset; 
  61.  
  62.     //the first point
  63.     var path = thestar.addPath(outRad*Math.cos(startAngle), -outRad*Math.sin(startAngle), 0); 
  64.  
  65.     while(thestar.paths.length > 1)
  66.     thestar.deletePath(1); 
  67.  
  68.     // the second point
  69.     path.addKnot(inRad*Math.cos(startAngle+anglePerKnot), -inRad*Math.sin(startAngle+anglePerKnot), 1); 
  70.     var currentAngle; 
  71.  
  72.     for(currentAngle = startAngle+anglePerPoint; currentAngle < endAngle; currentAngle += anglePerPoint)
  73.     {
  74.         //outerPoint
  75.         path.addKnot(outRad*Math.cos(currentAngle), -outRad*Math.sin(currentAngle), path.knots.length); 
  76.         //innerPoint
  77.         path.addKnot(inRad*Math.cos(currentAngle+anglePerKnot), -inRad*Math.sin(currentAngle+anglePerKnot), path.knots.length); 
  78.     }
  79.     path.closed = true; 
  80.     comp.restoreSelection();
  81. }
  82.  
  83.